﻿using FAS.DAL.Entity;
using FAS.DAL.Utils;
using FAS.WEB.Util;
using System;
using System.Data.SqlClient;
using System.IO;


namespace FAS.WEB.Views
{
    public partial class BackupDb: System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MyUser user = WebUtil.checkLoginUser();
            clearError();
        }
        private void showError(string error)
        {
            errorBottomLabel.Text = errorTopLabel.Text = error;
            workPanel.Visible = false;
        }
        private void clearError()
        {
            errorBottomLabel.Text = errorTopLabel.Text = "";
            workPanel.Visible = true;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {

            string name = "FAS" + DateTime.Today.ToString("yyyyMMdd") + ".bak.zip";
            string file = Server.MapPath("~/Download/DbBackup/" + name);            
            try
            {
                new DbBackup().backup("FAS", file);               
                result.Text = string.Format("备份完成。请<a href='../Download/DbBackup/{0}'>点击下载.</a>", name);
            }
            catch (Exception error)
            {
                errorBottomLabel.Text = "数据备份失败。<br/>" + error.Message;
            }
        }
    }
}